<?php
class i_forms{
    /**
     * Render($Navigation)
     * @param <string> $Navigation (values: language, input, summary)
     */
    public function Render($navigation){
        switch($navigation){
            case 'language':{
                $_data = new i_data();
                $_data->setLng();
                $_data->getLngConstants();
                $_data->createDataSession();
                $result = $this->getLanguageForm();
            }break;
            case 'input': {
                $_data = new i_data();
                $_data->setLng();
                $_data->getLngConstants();
                $result = $result = $this->getInputForm();
            }break;
            case 'summary': {
                $_data = new i_data();
                $_data->setLng();
                $_data->getLngConstants();
                $rslt = $_data->saveCfgMakeDB();
                
                switch($rslt){
                    case '_INPUTDATA_ERR_': $result = $this->getInputErrorMessage(); break;
                    case '_PSSWDMATCH_ERR_': $result = $this->getPsswdMatchErrorMessage(); break;
                    case '_DBCONNECTION_ERR_': $result = $this->getDBConnectionErrorMessage(); break;
                    case '_FWRITABLE_ERR_': $result = $this->getWriteableErrorMessage(); break;
                    default: $result = $this->getSummaryForm(); break;
                }

            }break;
            default:  {
                $_data = new i_data();
                $_data->setLng();
                $_data->getLngConstants();
                $result = $this->getLanguageForm();
            }break;
        }

        return $this->getDocumentHeader().$result.$this->getDocumentFooter();
    }

    private function getDocumentHeader(){
        return '
            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
            <html>
            <head>
                <title>Open Win Shop installation</title>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8;" >
            </head>
            <body style="font-family:verdana; font-size:10px;">
        ';
    }

    private function getDocumentFooter(){
        return '
            </body>
        ';
    }

    private function getLanguageForm(){
        $_data = new i_data();

        $result = '
            <center>
                <img src="install/imgs/lng.png" alt="">
                <form action="install.php" method="post">
                    <input type="hidden" name="navigation" id="navigation" value="input">
                    <br>
                    <table cellspacing="5" cellpadding="5" style="width: 400px; font-size: 10px; border: 10px solid silver;">
                        <tr>
                            <td colspan="2" style="font-size:14px; font-weight:bold; text-align: center;">
                                '._i18n_install_SELECT_YOUR_LANGUAGE_.'
                            </td>
                        <tr>
                            <td style="vertical-align: middle; text-align: right;">
                                <select name="lngCode" id="lngCode">
                                    '.$_data->getSelOpt_LngList().'
                                </select>
                            </td>
                            <td style="vertical-align: middle; text-align: left;">
                                <input type="image" src="install/imgs/refresh.png" value="'._i18n_install_REFRESH_.'" onmousedown="javascript:document.getElementById(\'navigation\').value=\'language\';">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <br><br>
                                '._i18n_install_LICENCE_TEXT1_.' (<a href="licence.html" target="_blank">'._i18n_install_FULL_TEXT_OF_THE_LICENCE_.'</a>)
                                <br><br>
                                '._i18n_install_LICENCE_TEXT2_.' (<a href="licence.html" target="_blank">'._i18n_install_FULL_TEXT_OF_THE_LICENCE_.'</a>)
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <br><br><br>
                                <center>
                                    <input type="image" src="install/imgs/next.png" value="'._i18n_install_NEXT_.'">'._i18n_install_NEXT_.'
                                </center>
                            </td>
                        </tr>
                    </table>                    
                </form>
            </center>
        ';

        return $result;
    }

    private function getInputForm(){
        $_data = new i_data();
        $sess = $_data->loadDataSession();

        $result = '
            <center>
                <img src="install/imgs/setup.png" alt="">
                <form action="install.php" method="post">
                    <input type="hidden" name="navigation" id="navigation" value="summary">
                    <table cellspacing="5" cellpadding="5" style="width: 400px; font-size: 10px; border: 10px solid silver;">
                        <tr>
                            <td colspan="2" style="font-size:14px; font-weight:bold; text-align: center;">
                                '._i18n_install_FILL_CONFIGARATION_VALUES_.'
                            </td>
                        <tr>
                        <tr>
                            <td>
                                '._i18n_install_SERVER_SUBDIRECTORY_.'
                            </td>
                            <td>
                                <input type="text" name="subdirectory" id="subdirectory" value="'.$sess['subdirectory'].'">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="color:silver;font-size:14px;">

                                '._i18n_install_DATABASE_SETUP_.'
                                <table style="font-size:10px;">
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_DATABASE_NAME_.'
                                        </td>
                                        <td>
                                            <input type="text" name="dbname" id="dbname" value="'.$sess['dbname'].'">*
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_SOCKET_.'
                                        </td>
                                        <td>
                                            <input type="text" name="dbsocket" id="dbsocket" value="'.$sess['dbsocket'].'">*
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_USER_.'
                                        </td>
                                        <td>
                                            <input type="text" name="dbuser" id="dbuser" value="'.$sess['dbuser'].'">*
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_PASSWORD_.'
                                        </td>
                                        <td>
                                            <input type="password" name="dbpsswd" id="dbpsswd" value="">
                                        </td>
                                    </tr>                                    
                                </table>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="color:silver;font-size:14px;">

                                '._i18n_install_ADMIN_ACCOUNT_SETUP_.'
                                <table style="font-size:10px;">
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_LOGIN_NAME_.'
                                        </td>
                                        <td>
                                            <input type="text" name="admuser" id="admuser" value="'.$sess['admuser'].'">*
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_PASSWORD_.'
                                        </td>
                                        <td>
                                            <input type="password" name="admpsswd" id="admpsswd" value="">*
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:150px; padding-left:10px;">
                                            '._i18n_install_REPEAT_PASSWORD_.'
                                        </td>
                                        <td>
                                            <input type="password" name="admrepeatpsswd" id="admrepeatpsswd" value="">*
                                        </td>
                                    </tr>
                                </table>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" style="color:silver;">
                                <center>
                                    <table style="font-size:10px;">
                                        <tr>
                                            <td>
                                                '._i18n_install_BACK_.'
                                            </td>
                                            <td>
                                                <input type="image" src="install/imgs/back.png" value="'._i18n_install_BACK_.'" onmousedown="javascript:document.getElementById(\'navigation\').value=\'language\';">
                                            </td>
                                            <td style="padding-left:10px;">
                                                <input type="image" src="install/imgs/next.png" value="'._i18n_install_NEXT_.'">
                                            </td>
                                            <td>
                                                '._i18n_install_NEXT_.'
                                            </td>
                                        </tr>
                                    </table>
                                </center>
                            </td>
                        </tr>
                    </table>
                </form>
            </center>
        ';

        return $result;
    }

    private function getSummaryForm(){
         return '
            <center>
                <table style="width: 400px; font-size: 10px; border: 10px solid silver;">
                    <tr>
                        <td>
                            <form action="index.php" method="post">
                                <center>
                                    <img src="install/imgs/ok.png" alt="">
                                    <font style="font-size:22px; font-weight:bold; font-family:verdana;">'._i18n_install_INSTALLATION_IS_SUCCESSFUL_.'</font>
                                    <br><br>
                                    '._i18n_install_CAN_NOT_BE_CONTINUED_UNLESS_YOU_DELETE_THE_INSTALLATION_.'
                                    <br><br>
                                    '._i18n_install_HINT_.': <i><small>'._i18n_install_YOU_HAVE_TO_REMOVE_INSTALL_DIRECTORY_AND_INSTALL_FILE_FOR_SAFETY_REASONS_.'</small></i>
                                    <br><br><br>
                                    <input type="image" src="install/imgs/ok.png" value="'._i18n_install_DONE_.'">'._i18n_install_DONE_.'
                                </center>
                            </form>
                        </td>
                    </tr>
                </table>
            </center>
        ';
    }

    private function getInputErrorMessage(){
        return '
            <center>
                <table style="width: 400px; font-size: 10px; border: 10px solid silver;">
                    <tr>
                        <td>
                            <form action="install.php" method="post">
                                <center>
                                    <input type="hidden" name="navigation" id="navigation" value="input">
                                    <img src="install/imgs/cancel.png" alt="">
                                    <font style="font-size:22px; font-weight:bold; font-family:verdana;">'._i18n_install_INPUT_DATA_ERROR_.'</font>
                                    <br><br>
                                    '._i18n_install_YOU_HAVENT_ENTERED_ALL_REQUIRED_DATA_.'
                                    <br><br>
                                    '._i18n_install_HINT_.': <i><small>'._i18n_install_YOU_HAVE_TO_TYPE_ALL_FIELDS_MARKED_BY_STAR_.'</small></i>
                                    <br><br><br>
                                    <input type="image" src="install/imgs/back.png" value="'._i18n_install_BACK_.'">'._i18n_install_BACK_.'
                                </center>
                            </form>
                        </td>
                    </tr>
                </table>
            </center>
        ';
    }

    private function getPsswdMatchErrorMessage(){
        return '
            <center>
                <table style="width: 400px; font-size: 10px; border: 10px solid silver;">
                    <tr>
                        <td>                            
                            <form action="install.php" method="post">
                                <center>
                                    <input type="hidden" name="navigation" id="navigation" value="input">
                                    <img src="install/imgs/cancel.png" alt="">
                                    <font style="font-size:22px; font-weight:bold; font-family:verdana;">'._i18n_install_PASSWORD_INPUT_ERROR_.'</font>
                                    <br><br>
                                    '._i18n_install_PASSWORD_PASSWORD_AND_REPEATED_PASSWORD_DONT_MATCH_.'
                                    <br>
                                    '._i18n_install_PLEASE_FILL_PASSWORDS_AGAIN_.'
                                    <br><br>
                                    '._i18n_install_HINT_.': <i><small>'._i18n_install_PASSWORD_HAS_TO_BE_SAME_AS_REPEATED_PASSWORD_IN_ADMIN_ACCOUNT_SETUP_PART_.'</small></i>
                                    <br><br><br>
                                    <input type="image" src="install/imgs/back.png" value="'._i18n_install_BACK_.'">'._i18n_install_BACK_.'
                                </center>
                            </form>
                        </td>
                    </tr>
                </table>
            </center>
        ';
    }

    private function getDBConnectionErrorMessage(){
        return '
            <center>
                <table style="width: 400px; font-size: 10px; border: 10px solid silver;">
                    <tr>
                        <td>
                            <form action="install.php" method="post">
                                <center>
                                    <input type="hidden" name="navigation" id="navigation" value="input">
                                    <img src="install/imgs/cancel.png" alt="">
                                    <font style="font-size:22px; font-weight:bold; font-family:verdana;">'._i18n_install_DB_CONNECTION_ERROR_.'</font>
                                    <br><br>
                                    '._i18n_install_ENTERED_VALUES_ARE_WRONG_.'
                                    <br><br>
                                    '._i18n_install_HINT_.': <i><small>'._i18n_install_CHECK_AND_CORRECT_VALUES_IN_DATABASE_SETUP_PART_.'</small></i>
                                    <br><br><br>
                                    <input type="image" src="install/imgs/back.png" value="'._i18n_install_BACK_.'">'._i18n_install_BACK_.'
                                </center>
                            </form>
                        </td>
                    </tr>
                </table>
            </center>
        ';
    }

    private function getWriteableErrorMessage(){
        return '
            <center>
                <table style="width: 400px; font-size: 10px; border: 10px solid silver;">
                    <tr>
                        <td>
                            <form action="install.php" method="post">
                                <center>
                                    <input type="hidden" name="navigation" id="navigation" value="input">
                                    <img src="install/imgs/cancel.png" alt="">
                                    <font style="font-size:22px; font-weight:bold; font-family:verdana;">'._i18n_install_ERROR_WRITING_TO_FILE_.'</font>
                                    <br><br>
                                    '._i18n_install_SOME_OF_NEXT_FILES_.':
                                    <br>
                                    ".htaccess", "definitions.inc.php"
                                    <br>
                                    '._i18n_install_IS_NOT_WRITABLE_.'
                                    <br><br>
                                    '._i18n_install_HINT_.': <i><small>'._i18n_install_PLEASE_SET_THEIR_RIGHTS_TO_WRITING_.'</small></i>
                                    <br><br><br>
                                    '._i18n_install_BACK_.'<input type="image" src="install/imgs/back.png" value="'._i18n_install_BACK_.'">
                                </center>
                            </form>
                        </td>
                    </tr>
                </table>
            </center>
        ';
    }
}
?>
